/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mii.dao.impl;

import entity.Pelanggan;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import mii.dao.PelangganDAO;

/**
 *
 * @author Sven
 */
public class PelangganDAOImpl extends GenericDAOImpl implements PelangganDAO{

    public PelangganDAOImpl(EntityManager em) {
        super(em);
    }
    
    @Override
    public Pelanggan getById(long id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        return this.em.find(Pelanggan.class, id);
    }

    @Override
    public List<Pelanggan> getAll() {
    //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        return this.em.createQuery("SELECT g FROM Pelanggan g").getResultList();
    }

   

    @Override
    public Pelanggan getByNopol(String nopol) {
       // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        return (Pelanggan)this.em.createQuery("Select g FROM Pelanggan g WHERE g.nopol = :param").setParameter("param", nopol).getSingleResult();
    }

    @Override
    public List<Pelanggan> getAllByNama(String nama) {
       // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        return this.em.createQuery("SELECT g FROM Pelanggan g WHERE g.nama LIKE :param").setParameter("param", "%"+nama+"%").getResultList();
    }
    
}
